#! /usr/bin/env python
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import base64

key = 'aoting_012345678'  # 16 byte key
iv = 'robot_0123456789'  # 16 byte IV
# 加密函数
def aes_encrypt(data):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    data = cipher.encrypt(data + (16 - len(data) % 16) * chr(16 - len(data) % 16))
    return base64.b64encode(data)

# 解密函数
def aes_decrypt(encrypted_data):
    encrypted_data = base64.b64decode(encrypted_data)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    decrypted_data = cipher.decrypt(encrypted_data)
    padding_length = ord(decrypted_data[-1])
    return decrypted_data[:-padding_length]

# 测试加密和解密函数
# data = 'aaaa'

# encrypted_data = aes_encrypt(data)
# decrypted_data = aes_decrypt(encrypted_data)
# print('Encrypted:', encrypted_data)
# print('Decrypted:', decrypted_data)